
<?php

//Author: Atef Sami

include 'functions.php';
include 'statics.php';
if (isset($_GET['paper_id']))
{
    // get the latest version of the current paper
    $v = get_latest_version($_GET['paper_id']);
	$version = mysql_real_escape_string($v);
    //  fetch the path of the latest version
    $rsResult = rsSelect("path", "version", array("version_id=", $version)); 
    if (is_string($rsResult))
        echo $rsResult;
    else
    { //add appropriate headers then load the pdf into the page
        $row = mysql_fetch_assoc($rsResult);
        header("Content-type: application/pdf");
        header('Content-Disposition: inline;filename="' . basename($row['path']) . '"');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Content-Length: ' . filesize($row['path']));
        ob_clean();
        readfile($row['path']);
    }
}
// End of documentation
?>
